/**
 * @author        Nicolas Bottarini <nicolasbottarini@gmail.com>, 404 <http://www.proyecto404.com>
 * @version       $Rev: 3 $
 * @lastrevision  $Date: 2011-09-12 16:45:37 +0000 (Mon, 12 Sep 2011) $	 
 */
package com.proyecto404.core.collections {
	import com.proyecto404.core.BaseObject;
	import com.proyecto404.core.Check;
	import com.proyecto404.core.exception.InvalidOperationException;
	import com.proyecto404.core.exception.NotImplementedException;
	
	public class ReadOnlySet extends BaseObject implements ISet	{
		private var _set:ISet;
		
		public function ReadOnlySet(set:ISet) {
			_set = set;
		}
		
		public function withValue(value:*):ISet {
			throw new InvalidOperationException("Cannot change readonly set");
		}
		
		public function withValuesFrom(values:*):ISet {
			throw new InvalidOperationException("Cannot change readonly set");
		}
		
		public function getOne():* {
			return _set.getOne();
		}
		
		public function union(set:ISet):ISet {
			return _set.union(set);
		}
		
		public function subtract(set:ISet):ISet {
			return _set.subtract(set);		
		}
		
		public function intersect(set:ISet):ISet {
			return _set.intersect(set);
		}
		
		public function count():int {
			return _set.count();
		}
		
		public function isEmpty():Boolean {
			return _set.isEmpty();
		}
		
		public function contains(value:*):Boolean {
			return _set.contains(value);
		}
		
		public function clear():void {
			throw new InvalidOperationException("Cannot change readonly set");
		}
		
		public function toList():IList {
			return _set.toList();
		}
		
		public function toArray():Array {
			return _set.toArray();
		}
		
		public function toSet():ISet {
			return this;
		}
		
		public function add(value:*):void {
			throw new InvalidOperationException("Cannot change readonly set");
		}
		
		public function remove(value:*):void {
			throw new InvalidOperationException("Cannot change readonly set");
		}
		
		public function removeFromArray(array:Array):void {
			throw new InvalidOperationException("Cannot change readonly set");
		}
		
		public function removeFromCollection(collection:ICollection):void {
			throw new InvalidOperationException("Cannot change readonly set");
		}

		public function addFromArray(array:Array):void {
			throw new InvalidOperationException("Cannot change readonly set");
		}
		
		public function addFromCollection(collection:ICollection):void {
			throw new InvalidOperationException("Cannot change readonly set");
		}
		
		public function asReadOnly():ICollection {
			return this;
		}
		
		public function getIterator():IIterator {
			return _set.getIterator();
		}
		
		public function implode(separator:String = ","):String {
			return _set.implode(separator);
		}
		
		public override function toString():String {
			return "ReadOnlySet{" + implode() + "}";
		}
		
		public function collect(criteria:Function):ICollection {
			return _set.collect(criteria);
		}
		
		public function forEach(callback:Function):void {
			_set.forEach(callback);
		}
		
		public function map(convert:Function):ICollection {
			return _set.map(convert);
		}
		
		public function all(criteria:Function):Boolean {
			return _set.all(criteria);
		}
		
		public function any(criteria:Function):Boolean {
			return _set.any(criteria);
		}
		
		public override function equals(value:*):Boolean {
			if(!(value is ReadOnlySet)) return false;
			return _set.equals(ReadOnlySet(value)._set);
		}
	}
}